<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="../../taglib.jsp"%>
<%@ page import="dragon.model.fieldTemplate.FieldTemplateContainer"%>
<%@ page import="dragon.model.bizObject.BizObjectContainer"%>
<%@ page import="dragon.model.table.TableContainer"%>
<%@ page import="dragon.core.util.Reflect"%>
<%@ page import="dragon.core.util.StringUtils"%>
<%@ page import="dragon.model.base.ModelDescribe"%>
<%@ page import="dragon.model.base.Util"%>
<%@ page import="java.lang.reflect.Field"%>
<%@ page import="java.lang.reflect.Method"%>
<%@ page import="java.lang.annotation.Annotation"%>
<%@ page import="java.util.Map"%>
<%@ page import="java.util.Map.Entry"%>
<%@ page import="java.util.Set"%>
<%@ page import="java.util.Iterator"%>
<%@ page import="java.util.List"%>

<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<base href="<%=basePath%>" />
<title>fieldDetail</title>
<%@ include file="/webmodules/console/css.jsp"%>
<%@ include file="/webmodules/console/js.jsp"%>
<script type="text/javascript">
	function viewMore(type, code) {
		top.showWindow('${param.window}ModelView', '模型查看', 'webviews/model/view.jsp?window=${param.window}ModelView&type=' + type + '&code=' + code, null, null, null, true);
	}
</script>
</head>
<body style="overflow: auto;">
	<c:if test="${param.window!=null&&param.window!=''}">
		<div>
			<a href="javascript:void(0);" class="easyui-linkbutton" iconCls="icon-cancel" onclick="top.closeWindow('${param.window}');">关闭</a>
		</div>
	</c:if>
	<%
		String type = request.getParameter("type");
		String code = request.getParameter("code");

		//参数完整
		if (type != null && !StringUtils.isEmpty(type) && code != null && !StringUtils.isEmpty(code)) {
			Object model = null;
			if ("FieldTemplate".equals(type)) {
				model = FieldTemplateContainer.get(code);
			} else if ("Table".equals(type)) {
				model = TableContainer.get(code);
			} else if ("BizObject".equals(type)) {
				model = BizObjectContainer.get(code);
			}
			if (model != null) {
				Field[] fields = Reflect.getDeclaredFields(model.getClass());
	%>
	<table border="1" width="100%">
		<thead>
			<tr>
				<td colspan="3"><%=model.getClass().getName()%>---${param.type=='fieldTemplate'?'字段模板':param.type=='table'?'数据模型':'业务模型' }--<%=model.hashCode() %></td>
			</tr>
			<tr>
				<th width="50%">说明</th>
				<th width="10%">字段</th>
				<th width="40%">值</th>
			</tr>
		</thead>
		<tbody>
			<%
				String fieldName = null;
				Method getMethod = null;
				ModelDescribe annotation = null;
				boolean isRuntimeField = false;
				String description = "";
				String fieldType = null;
				Object value = null;
				for (Field field : fields) {
					fieldName = field.getName();
					//取get方法，判断obj2中属性值是否存在
					getMethod = Reflect.getGetterMethod(model.getClass(), field);
					if (getMethod == null) {
						continue;
					}

					isRuntimeField = false;
					description = "";
					annotation = field.getAnnotation(ModelDescribe.class);
					if (annotation != null) {
						isRuntimeField = annotation.runtime();
						description = annotation.annotation();
					}

					fieldType = field.getType().getSimpleName();

					value = getMethod.invoke(model);
			%>
			<tr style="color: <%=isRuntimeField ? "red" : "black"%>">
				<td><%=description%></td>
				<td><%=fieldName%></td>
				<td><%=Util.toHtmlString(value)%></td>
			</tr>
			<%
				}
			%>
		</tbody>
	</table>
	<%
		}
		}
	%>
	<c:if test="${param.window!=null&&param.window!=''}">
		<div>
			<a href="javascript:void(0);" class="easyui-linkbutton" iconCls="icon-cancel" onclick="top.closeWindow('${param.window}');">关闭</a>
		</div>
	</c:if>
</body>
</html>
